package br.edu.unilasalle.simon_test.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.springframework.util.ResourceUtils;

public class Utils {

	public static final String TEST_CONFIG_PROPERTIES_PATH = "classpath:test-config.properties";

	public static final long SELENIUM_WAIT_TIMEOUT = 20;
	
	public static final long PAGE_ELEMENT_TIMEOUT = 60;

	public static Properties loadTestProperties() throws FileNotFoundException, IOException {
		File file = ResourceUtils.getFile(TEST_CONFIG_PROPERTIES_PATH);
		InputStream input = new FileInputStream(file);
		Properties prop = new Properties();
		prop.load(input);
		input.close();
		return prop;
	}

	public static String getTestProperty(String propertyKey) {
		try {
			Properties prop = loadTestProperties();
			return prop.getProperty(propertyKey);
		} catch (Exception e) {
			throw new IllegalStateException("Não foi possível carregar a propriedade " + propertyKey + ". Erro: "
					+ e.getMessage());
		}
	}

}
